import java.io.IOException;
import java.util.logging.*;

/**
 * This is the Appointment Class. 
 * It holds all the information of an individual's appointment.
 */
public class Appointment {
	private int date;
	
	private int time;
	
	private String reason;
	
	private Doctor doctor;
	
	private String patient;
	
	private boolean hasOccurred;
	
	private static Logger appointmentLog = Logger.getLogger(Appointment.class.getName());
	
	static{
		ConsoleHandler console = new ConsoleHandler();
		console.setLevel(Level.ALL);
		console.setFormatter(new ThunderDragonHtmlFormatter());
		appointmentLog.addHandler(console);
		appointmentLog.setLevel(Level.ALL);
		
		try {
			FileHandler fh = new FileHandler("AppointmentLog.txt");
			fh.setFormatter(new ThunderDragonHtmlFormatter());
			appointmentLog.addHandler(fh);
		} catch (SecurityException e) {
			// TODO Auto-generated catch block
			appointmentLog.severe("Failure: Security exception thrown " +
					"when trying to create a new handler in Appointment.java.");
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			appointmentLog.severe("Failure: I/O exception thrown " +
					"when trying to create a new handler in Appointment.java.");
			e.printStackTrace();
		}
		
	}
	
	/**
	 * Constructor for Appointment.
	 * @param date int The date of the appointment
	 * @param time int The time of the appointment
	 * @param reason String The reason of the appointment
	 * @param doctor String The doctor overseeing the appointment
	 * @param patient String The patient that made the appointment
	 */
	public Appointment(int date, int time, String reason, Doctor doctor,
			String patient, boolean hasOccurred) {
		
		appointmentLog.entering(this.getClass().getName(), "Appointment Constructor",  
				new Object[] {date, time, reason, doctor, patient, hasOccurred});
		
		this.date = date;
		this.time = time;
		this.reason = reason;
		this.doctor = doctor;
		this.patient = patient;
		hasOccurred = false;
		
		appointmentLog.exiting(this.getClass().getName(), "Appointment Constructor");
	}
	
	/**
	 * Method getDate.
	 * @return int date The date
	 */
	public int getDate() {
		appointmentLog.finest("Got the dates.");
		return date;
	}

	/**
	 * Method setDate.
	 * @param date int The specified date that the date variable will be set to
	 */
	public void setDate(int date) {
		this.date = date;
		appointmentLog.finest("Exiting setDate() in class Appointment.");
	}

	/**
	 * Method getTime.
	 * @return int time The current time
	 */
	public int getTime() {
		appointmentLog.finest("Got the time.");
		return time;
	}

	/**
	 * Method setTime.
	 * @param time int The time that the time variable will be set to
	 */
	public void setTime(int time) {
		this.time = time;
		appointmentLog.finest("Exiting setTime() in class Appointment.");
	}

	/**
	 * Method getReason.
	 * @return String reason The reason for coming.
	 */
	public String getReason() {
		appointmentLog.finest("Got the reason.");
		return reason;
	}

	/**
	 * Method setReason.
	 * @param reason String The reason being set
	 */
	public void setReason(String reason) {
		this.reason = reason;
		appointmentLog.finest("Exiting setReason() in class Appointment.");
	}

	/**
	 * Method getDoctor.
	 * @return Doctor The doctor of the appointment
	 */
	public Doctor getDoctor() {
		appointmentLog.finest("Got the doctor.");
		return doctor;
	}

	/**
	 * Method setDoctor.
	 * @param doctor Doctor The doctor being set to the appointment.
	 */
	public void setDoctor(Doctor doctor) {
		this.doctor = doctor;
		appointmentLog.finest("Exiting setDoctor() in class Appointment.");
	}

	/**
	 * Method getPatient.
	 * @return String patient The patient
	 */
	public String getPatient() {
		appointmentLog.finest("Got the patient.");
		return patient;
	}

	/**
	 * Method setPatient.
	 * @param patient String The patient that the is being set
	 */
	public void setPatient(String patient) {
		this.patient = patient;
		appointmentLog.finest("Exiting setPatient() in class Appointment.");
	}

	/**
	 * This method determines if the day of the appointment has already passed or not.
	 * @return boolean hasOccurred
	 */
	public boolean hasOccurred(){
		appointmentLog.finest("Got hasOccurred.");
        return hasOccurred;	
	}
	
	/**
	 * This method sets the hasOccurred variable to the specified state.
	 * @param hasOccurred Whether the appointment has occurred or not
	 */
	public void setHasOccurred(boolean hasOccurred){
		this.hasOccurred = hasOccurred;
		appointmentLog.finest("Exiting setHasOccured() in class Appointment.");
	}
	
	@Override
	
	/**
	 * Converts to string.
	 * @return the String.
	 */
	public String toString() {
		return "An appointment has been made for: " + patient + " with Dr. " + 
		doctor + "on " + date + " at " + time + " because of " + reason;
		}

}
